package com.hctforgreen.greenservice.model;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * 5、资料下载
 * @author Tallen Zhai
 *
 */
public class BookZipTxtEntity extends BaseEntity {

	private static final long serialVersionUID = -8739523329733588538L;

	public List<EntryTitleEntity> entryTitleList = null;
	
	public List<EntryEntity> entryList = null;
	
	private final static String ENTRY_TITLE_LIST = "entryTitleList";
	
	private final static String ENTRY_LIST = "entryList";
	public static BookZipTxtEntity parse(JSONObject jsonObject)throws JSONException{
		BookZipTxtEntity bean = new BookZipTxtEntity();
		
		/**
		 * 解析entryTitleList节点
		 */
		if (jsonObject.has(ENTRY_TITLE_LIST)) {
			
			JSONArray jsonArray = jsonObject.getJSONArray(ENTRY_TITLE_LIST);
				
			bean.entryTitleList = new ArrayList<EntryTitleEntity>();
			for (int i = 0; i < jsonArray.length(); i++) {
				JSONObject object = jsonArray.getJSONObject(i);
				EntryTitleEntity entity = EntryTitleEntity.parse(object);
				bean.entryTitleList.add(entity);
			}
			
		}
		/**
		 * 解析entryList节点
		 */
		if (jsonObject.has(ENTRY_LIST)) {
			
			JSONArray jsonArray = jsonObject.getJSONArray(ENTRY_LIST);
				
			bean.entryList = new ArrayList<EntryEntity>();
			for (int i = 0; i < jsonArray.length(); i++) {
				JSONObject object = jsonArray.getJSONObject(i);
				EntryEntity entity = EntryEntity.parse(object);
				bean.entryList.add(entity);
			}
			
		}
		return bean;
	}
	public static class EntryTitleEntity extends BaseEntity {

		private static final long serialVersionUID = 7590037277344752801L;
		public String id = "";
		public String bookId = "";
		
		public String parentId = "";
		public String level = "";
		public String titleContents = "";
		
		public final static String ID = "id";
		public final static String BOOK_ID = "bookId";
		public final static String PARENT_ID = "parentId";
		public final static String LEVEL = "level";
		public final static String TITLE_CONTENTS = "titleContents";
		
		
		public static EntryTitleEntity parse(JSONObject jsonObject)
				throws JSONException {
			EntryTitleEntity bean = new EntryTitleEntity();
			
			if (jsonObject.has(ID)) {
				bean.id = jsonObject.getString(ID);
			}
			if (jsonObject.has(BOOK_ID)) {
				bean.bookId = jsonObject.getString(BOOK_ID);
			}
			if (jsonObject.has(PARENT_ID)) {
				bean.parentId = jsonObject.getString(PARENT_ID);
			}
			
			if (jsonObject.has(LEVEL)) {
				bean.level = jsonObject.getString(LEVEL);
			}
			if (jsonObject.has(TITLE_CONTENTS)) {
				bean.titleContents = jsonObject.getString(TITLE_CONTENTS);
			}
			return bean;
		}
	}
	public static class EntryEntity extends BaseEntity {

		private static final long serialVersionUID = 3393175299862529528L;
		public String entryTitleId = "";
		public String contents = "";
		
		
		public final static String ENTRY_TITLE_ID = "entryTitleId";
		public final static String CONTENTS = "contents";
		
		//=========页面中才用的到=========
		public String bookId = "";

		public String titleContents = "";
		public static EntryEntity parse(JSONObject jsonObject)
				throws JSONException {
			EntryEntity bean = new EntryEntity();
			
			if (jsonObject.has(ENTRY_TITLE_ID)) {
				bean.entryTitleId = jsonObject.getString(ENTRY_TITLE_ID);
			}
			if (jsonObject.has(CONTENTS)) {
				bean.contents = jsonObject.getString(CONTENTS);
			}
			
			return bean;
		}
	}
	
}
